﻿import idv.ben.picasawebservice4flash.data.*;
import idv.ben.picasawebservice4flash.service.*;

class idv.ben.picasawebservice4flash.data.AlbumEntry{
	
	private var __id:String;
	private var __published:String;
	private var __updated:String;
	private var __title:String;
	private var __summary:String;
	private var __rights:String;
	private var __author_name:String;
	private var __author_uri:String;
	private var __gphoto:AlbumEntryGPhoto;
	private var __media:AlbumEntryMedia;
	
	/**
	* 建構子
	* @param node 由 http://picasaweb.google.com/data/feed/api/user/<i>userID</i>?kind=<i>kinds</i> 取回的 xml 中，&lt;feed&gt; 節點下的 &lt;entry&gt; 節點。
	*/
	function AlbumEntry(node:XMLNode){
		parseFeed(node);
	}
	
	private function parseFeed(node:XMLNode):Void{
		__gphoto = new AlbumEntryGPhoto();
		__media = new AlbumEntryMedia();
		
		for(var i:Number=0; i<node.childNodes.length; i++){
			if(node.childNodes[i].nodeName.indexOf("gphoto:") == 0){
				__gphoto.applyParam(node.childNodes[i].nodeName.split("gphoto:").join(""), node.childNodes[i].firstChild);
				continue;
			}					
			switch(node.childNodes[i].nodeName.toLowerCase()){
				case "id".toLowerCase():
				case "published".toLowerCase():
				case "updated".toLowerCase():
				case "title".toLowerCase():
				case "summary".toLowerCase():
				case "rights".toLowerCase():
					this["__" + node.childNodes[i].nodeName] = node.childNodes[i].firstChild;
					break;
				case "author".toLowerCase():
					__author_name = node.childNodes[i].childNodes[0].firstChild;
					__author_uri = node.childNodes[i].childNodes[1].firstChild;
					break;
				case "media:group".toLowerCase():
					for(var j:Number=0; j<node.childNodes[i].childNodes.length; j++){
						switch(node.childNodes[i].childNodes[j].nodeName.toLowerCase()){
							case "media:title".toLowerCase():
							case "media:description".toLowerCase():
							case "media:keywords".toLowerCase():
							case "media:credit".toLowerCase():
								__media.applyParam(node.childNodes[i].childNodes[j].nodeName.split("media:").join(""), node.childNodes[i].childNodes[j].firstChild);
								break;
							case "media:content".toLowerCase():
							case "media:thumbnail".toLowerCase():
								__media.applyParam(node.childNodes[i].childNodes[j].nodeName.split("media:").join(""), node.childNodes[i].childNodes[j].attributes["url"]);
								break;
						}
					}
					break;
			}
		}
	}
	
	public function get id():String{return __id;}
	public function get published():String{return __published;}
	public function get updated():String{return __updated;}
	public function get title():String{return __title;}
	public function get summary():String{return __summary;}
	public function get rights():String{return __rights;}
	public function get author_name():String{return __author_name;}
	public function get author_uri():String{return __author_uri;}
	public function get gphoto():AlbumEntryGPhoto{return __gphoto;}
	public function get media():AlbumEntryMedia{return __media;}
}